<template>
    <div class="newsinfo-container">
        <!-- 大标题 -->
        <h3 class="title">{{newsInfo.title}}</h3>
        <!-- 子标题 -->
        <p class="subtitle">
            <span>发表时间:{{newsInfo.add_time|dataFormat}}</span>
            <span>点击:{{newsInfo.click}}次</span>
        </p>
        <hr>
        <!-- 内容区域 -->
        <div class="content" v-html="newsInfo.content"></div>
        <!-- 评论子组件区域 -->
        <comment-box :id="this.id"></comment-box>
    </div>

</template>

<script>
import {Toast} from 'mint-ui'
import comment from '../subcomponents/comment.vue'
export default {
    components: {
        'comment-box':comment
    },
    data(){
        return {
            id:this.$route.params.id,//将url地址中传递的id值挂载到data上
            newsInfo:[]
        }
    },
    created(){
      this.getNewsInfo()
    },
    methods:{
        getNewsInfo(){//获取新闻详情
            this.$axios({
            method:'get',
            url:'/api/getnew/'+this.id,
        }).then((response) =>{          //这里使用了ES6的语法
            //console.log(response)       //请求成功返回的数据
            if(response.data.status===0){
                this.newsInfo = response.data.message[0]
            }else{
                Toast('获取新闻详情失败！')
            }
        }).catch((error) =>{
            console.log(error)       //请求失败返回的数据
        })
    },
  }
}
</script>

<style lang="scss">
.newsinfo-container{
    padding: 0 4px;
    .title{
        font-size: 15px;
        text-align: center;
        margin: 15px;
        color: red;
        
    }
    .subtitle{
        font-size: 13px;
        color: #226aff;
        display: flex;
        justify-content: space-between;
    }
    .content{
        img{
            width: 100%;
        }
    }
}
</style>

